package com.bjsxt.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bjsxt.commons.DataGridModel;
import com.bjsxt.pojo.Staff;
import com.bjsxt.service.EmployeesService;
/**
 * 员工操作相关
 * @author 程应康
 */
@Controller
@RequestMapping("/Employees")
public class EmployeesController {
	@Autowired
	private EmployeesService employeesService;
	
//	@RequestMapping("showEmployees")
//	public String showEmployees() {
//		return "showEmployees";
//	}
	/**
	 * 操作所有用户
	 * @param page 当前页码
	 * @param rows 显示多少行
	 * @return 数据
	 */
	@RequestMapping("/findEmployees")
	@ResponseBody
	public DataGridModel findEmployees(@RequestParam(defaultValue="1") Integer page, @RequestParam(defaultValue="10") Integer rows ) {
		DataGridModel dgm = employeesService.findEmployees(page,rows);
		
		return dgm;
	}
	
	/**
	 * 添加一个用户
	 * @param staff 用户信息
	 * @return 是否添加成功
	 */
	@RequestMapping("/addEmployees")
	@ResponseBody
	public Integer addEmployees(Staff staff) {
		try {
			employeesService.addEmployees(staff);
			return 200;
		} catch (Exception e) {
			e.printStackTrace();
			return 500;
		}
	}
	
	@RequestMapping("/dropEmployees")
	@ResponseBody
	public Integer dropEmployees(Integer staffid) {
		try {
			employeesService.dropEmployees(staffid);
			System.out.println(staffid+"成功删除");
			return 200;
		} catch (Exception e) {
			e.printStackTrace();
			return 500;
		}
	}
	
	@RequestMapping("/modifyEmployees")
	@ResponseBody
	public Integer modifyEmployees(Staff staff) {
		try {
			employeesService.modifyEmployees(staff);
			return 200;
		} catch (Exception e) {
			e.printStackTrace();
			return 500;
		}
	}
}
